<template>
  <div class="about">
    <button @click="openApp">1111111111111</button>
  </div>
</template>
<script lang="ts">
import { Vue, Prop, Component, Emit } from "vue-property-decorator";
import CallApp from "callapp-lib";
@Component
export default class about extends Vue {
  isHidden: boolean = false;
  option = {
    scheme: {
      protocol: "zhihu",
    },
    intent: {
      package: "com.zhihu.android",
      scheme: "zhihu",
    },
    universal: {
      host: "oia.zhihu.com",
    },
    appstore: "https://itunes.apple.com/cn/app/id432274380",
    yingyongbao: "//a.app.qq.com/o/simple.jsp?pkgname=com.zhihu.android",
    fallback: "https://oia.zhihu.com/",
    timeout: 2000,
  };
  lib: any = "";
  openApp() {
    console.log(11111111111);
    // this.lib.open({
    //   path: "",
    //   param: {},
    //   callback: function () {
    //     console.log("失败回调");
    //     return;
    //   },
    // });
    let _this = this;
    // let iframe = document.createElement("iframe");
    // iframe.style.display = "none";
    // iframe.src = "weixin://";
    // document.body.appendChild(iframe);
    // iframe.click();
    // setTimeout(function () {
    //   document.body.removeChild(iframe);
    // }, 500);
    window.location.href = "weixin://"
    //当前时间戳
    let startTime = new Date().getTime();
    document.addEventListener("visibilitychange", function () {
      console.log(111);
      console.log(document.hidden, "hidden");
      if (document.hidden && new Date().getTime() - startTime <= 1000) {
        _this.isHidden = true;
      } else {
        _this.isHidden = false;
      }
      // document.hidden; //看下这个值
    });

    setTimeout(() => {
      if (!_this.isHidden) {
        window.location.href = "https://weixin.qq.com/";
      }
    }, 1000);
  }
  created() {
    try {
      this.lib = new CallApp(this.option);
      // this.lib.callback = function () {
      //   console.log("失败回调");
      //   return;
      // };
      console.log(this.lib);
    } catch {}
  }
}
</script>
